Micron Document
<!DOCTYPE html>
<html class="client-nojs vector-feature-night-mode-disabled vector-feature-language-in-header-enabled vector-feature-language-in-main-page-header-disabled vector-feature-page-tools-pinned-disabled vector-feature-toc-pinned-clientpref-1 vector-feature-main-menu-pinned-disabled vector-feature-limited-width-clientpref-1 vector-feature-limited-width-content-enabled vector-feature-custom-font-size-clientpref-1 vector-feature-appearance-pinned-clientpref-1 vector-sticky-header-enabled" lang="en" dir="ltr"><head>
<meta charset="UTF-8">
<title>Java Modeling Language</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="canonical" href="https://en.wikipedia.org/wiki/Java_Modeling_Language"> <link href="./mw/ext.pygments.css" rel="stylesheet" type="text/css">
<link href="./mw/skins.vector.icons.css" rel="stylesheet" type="text/css">
<link href="./mw/skins.vector.search.codex.styles.css" rel="stylesheet" type="text/css">
<link href="./mw/skins.vector.styles.css" rel="stylesheet" type="text/css">
<link href="./mw/user.styles.css" rel="stylesheet" type="text/css">
<meta name="ResourceLoaderDynamicStyles" content="">
<link rel="stylesheet" type="text/css" href="./mw/site.styles.css">
<link rel="stylesheet" type="text/css" href="./mw/noscript.css">
<link rel="stylesheet" type="text/css" href="./footer.css">
<link rel="stylesheet" type="text/css" href="./vector-2022.css">
</head>
<body class="skin--responsive skin-vector skin-vector-search-vue mediawiki ltr sitedir-ltr mw-hide-empty-elt ns-0 ns-subject page-Java_Modeling_Language rootpage-Java_Modeling_Language skin-vector-2022 action-view">
<div class="mw-page-container">
<div class="mw-page-container-inner">
<div class="mw-content-container">
<main id="content" class="mw-body">
<header class="mw-body-header vector-page-titlebar">
<h1 id="firstHeading" class="firstHeading mw-first-heading">
<span id="openzim-page-title" class="mw-page-title-main"><span class="mw-page-title-main">Java Modeling Language</span></span>
</h1>
</header>
<a id="top"></a>
<div id="bodyContent" class="vector-body ve-init-mw-desktopArticleTarget-targetContainer" aria-labelledby="firstHeading" data-mw-ve-target-container="">
<div id="mw-content-text" class="mw-body-content mw-content-ltr" lang="en" dir="ltr"><div class="mw-content-ltr mw-parser-output" lang="en" dir="ltr">
<style data-mw-deduplicate="TemplateStyles:r1251242444">
/* start https://en.wikipedia.org/ */


.mw-parser-output .ambox{border:1px solid #a2a9b1;border-left:10px solid #36c;background-color:#fbfbfb;box-sizing:border-box}.mw-parser-output .ambox+link+.ambox,.mw-parser-output .ambox+link+style+.ambox,.mw-parser-output .ambox+link+link+.ambox,.mw-parser-output .ambox+.mw-empty-elt+link+.ambox,.mw-parser-output .ambox+.mw-empty-elt+link+style+.ambox,.mw-parser-output .ambox+.mw-empty-elt+link+link+.ambox{margin-top:-1px}html body.mediawiki .mw-parser-output .ambox.mbox-small-left{margin:4px 1em 4px 0;overflow:hidden;width:238px;border-collapse:collapse;font-size:88%;line-height:1.25em}.mw-parser-output .ambox-speedy{border-left:10px solid #b32424;background-color:#fee7e6}.mw-parser-output .ambox-delete{border-left:10px solid #b32424}.mw-parser-output .ambox-content{border-left:10px solid #f28500}.mw-parser-output .ambox-style{border-left:10px solid #fc3}.mw-parser-output .ambox-move{border-left:10px solid #9932cc}.mw-parser-output .ambox-protection{border-left:10px solid #a2a9b1}.mw-parser-output .ambox .mbox-text{border:none;padding:0.25em 0.5em;width:100%}.mw-parser-output .ambox .mbox-image{border:none;padding:2px 0 2px 0.5em;text-align:center}.mw-parser-output .ambox .mbox-imageright{border:none;padding:2px 0.5em 2px 0;text-align:center}.mw-parser-output .ambox .mbox-empty-cell{border:none;padding:0;width:1px}.mw-parser-output .ambox .mbox-image-div{width:52px}@media(min-width:720px){.mw-parser-output .ambox{margin:0 10%}}@media print{body.ns-0 .mw-parser-output .ambox{display:none!important}}


/* end https://en.wikipedia.org/ */
</style>
<p>The <b>Java Modeling Language</b> (<b>JML</b>) is a <a href="Specification_language" title="Specification language">specification language</a> for <a href="Java_(programming_language)" title="Java (programming language)">Java</a> programs, using <a href="Hoare_logic" title="Hoare logic">Hoare style</a> <a href="Precondition" title="Precondition">pre-</a> and <a href="Postcondition" title="Postcondition">postconditions</a> and <a href="Invariant_(computer_science)" class="mw-redirect" title="Invariant (computer science)">invariants</a>, that follows the <a href="Design_by_contract" title="Design by contract">design by contract</a> paradigm. Specifications are written as <a href="Java_annotation" title="Java annotation">Java annotation</a> comments to the source files, which hence can be compiled with any Java <a href="Compiler" title="Compiler">compiler</a>.
</p><p>Various verification tools, such as a runtime assertion checker and the Extended Static Checker (<a href="ESC/Java" title="ESC/Java">ESC/Java</a>) aid development.
</p>
<meta property="mw:PageProp/toc">
<div class="mw-heading mw-heading2"><h2 id="Overview">Overview</h2></div>
<p>JML is a behavioural interface specification language for Java modules. JML provides <a href="Semantics" title="Semantics">semantics</a> to formally describe the behavior of a Java module, preventing ambiguity with regard to the module designers' intentions. JML inherits ideas from <a href="Eiffel_(programming_language)" title="Eiffel (programming language)">Eiffel</a>, <a href="Larch_family" title="Larch family">Larch</a> and the <a href="Refinement_Calculus" class="mw-redirect" title="Refinement Calculus">Refinement Calculus</a>, with the goal of providing rigorous formal semantics while still being accessible to any Java programmer. Various tools are available that make use of JML's behavioral specifications. Because specifications can be written as annotations in Java program files, or stored in separate specification files, Java modules with JML specifications can be compiled unchanged with any Java compiler.
</p>
<div class="mw-heading mw-heading2"><h2 id="Syntax">Syntax</h2></div>
<p>JML specifications are added to Java code in the form of annotations in comments. Java comments are interpreted as JML annotations when they begin with an @ sign. That is, comments of the form
</p>
<div class="mw-highlight mw-highlight-lang-java mw-content-ltr" dir="ltr"><pre><span class="w"> </span><span class="c1">//@ &lt;JML specification&gt;</span>
</pre></div>
<p>or
</p>
<div class="mw-highlight mw-highlight-lang-java mw-content-ltr" dir="ltr"><pre><span class="w"> </span><span class="cm">/*@ &lt;JML specification&gt; @*/</span>
</pre></div>
<p>Basic JML syntax provides the following keywords
</p>
<dl><dt><code>requires</code></dt>
<dd>Defines a <a href="Precondition" title="Precondition">precondition</a> on the <a href="Method_(computer_science)" class="mw-redirect" title="Method (computer science)">method</a> that follows.</dd>
<dt><code>ensures</code></dt>
<dd>Defines a <a href="Postcondition" title="Postcondition">postcondition</a> on the method that follows.</dd>
<dt><code>signals</code></dt>
<dd>Defines a postcondition for when a given <a href="Exception_handling" title="Exception handling">Exception</a> is thrown by the method that follows.</dd>
<dt><code>signals_only</code></dt>
<dd>Defines what exceptions may be thrown when the given precondition holds.</dd>
<dt><code>assignable</code></dt>
<dd>Defines which fields are allowed to be assigned to by the method that follows.</dd>
<dt><code>pure</code></dt>
<dd>Declares a method to be side effect free (like <code>assignable \nothing</code> but can also throw exceptions). Furthermore, a pure method is supposed to always either terminate normally or throw an exception.</dd>
<dt><code>invariant</code></dt>
<dd>Defines an <a href="Class_invariant" title="Class invariant">invariant property of the class</a>.</dd>
<dt><code>loop_invariant</code></dt>
<dd>Defines a <a href="Loop_invariant" title="Loop invariant">loop invariant</a> for a loop.</dd>
<dt><code>also</code></dt>
<dd>Combines specification cases and can also declare that a method is inheriting specifications from its supertypes.</dd>
<dt><code>assert</code></dt>
<dd>Defines a JML <a href="Assertion_(computing)" class="mw-redirect" title="Assertion (computing)">assertion</a>.</dd>
<dt><code>spec_public</code></dt>
<dd>Declares a protected or private variable public for specification purposes.</dd></dl>
<p>Basic JML also provides the following expressions
</p>
<dl><dt><code>\result</code></dt>
<dd>An identifier for the return value of the method that follows.</dd>
<dt><code>\old(&lt;expression&gt;)</code></dt>
<dd>A modifier to refer to the value of the <code>&lt;expression&gt;</code> at the time of entry into a method.</dd>
<dt><code>(\forall &lt;decl&gt;; &lt;range-exp&gt;; &lt;body-exp&gt;)</code></dt>
<dd>The <a href="Universal_quantifier" class="mw-redirect" title="Universal quantifier">universal quantifier</a>.</dd>
<dt><code>(\exists &lt;decl&gt;; &lt;range-exp&gt;; &lt;body-exp&gt;)</code></dt>
<dd>The <a href="Existential_quantifier" class="mw-redirect" title="Existential quantifier">existential quantifier</a>.</dd>
<dt><code>a ==&gt; b</code></dt>
<dd><code>a</code> implies <code>b</code></dd>
<dt><code>a &lt;== b</code></dt>
<dd><code>a</code> is implied by <code>b</code></dd>
<dt><code>a &lt;==&gt; b</code></dt>
<dd><code>a</code> if and only if <code>b</code></dd></dl>
<p>as well as standard <a href="Java_syntax" title="Java syntax">Java syntax</a> for logical and, or, and not. JML annotations also have access to Java objects, object methods and operators that are within the scope of the method being annotated and that have appropriate visibility. These are combined to provide formal specifications of the properties of classes, fields and methods. For example, an annotated example of a simple banking class may look like
</p>
<div class="mw-highlight mw-highlight-lang-java mw-content-ltr" dir="ltr"><pre><span class="kd">public</span><span class="w"> </span><span class="kd">class</span> <span class="nc">BankingExample</span>
<span class="p">{</span>
<span class="w"> </span>
<span class="w"> </span><span class="kd">public</span><span class="w"> </span><span class="kd">static</span><span class="w"> </span><span class="kd">final</span><span class="w"> </span><span class="kt">int</span><span class="w"> </span><span class="n">MAX_BALANCE</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">1000</span><span class="p">;</span><span class="w"> </span>
<span class="w"> </span><span class="kd">private</span><span class="w"> </span><span class="cm">/*@ spec_public @*/</span><span class="w"> </span><span class="kt">int</span><span class="w"> </span><span class="n">balance</span><span class="p">;</span>
<span class="w"> </span><span class="kd">private</span><span class="w"> </span><span class="cm">/*@ spec_public @*/</span><span class="w"> </span><span class="kt">boolean</span><span class="w"> </span><span class="n">isLocked</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="kc">false</span><span class="p">;</span><span class="w"> </span>
<span class="w"> </span>
<span class="w"> </span><span class="c1">//@ public invariant balance &gt;= 0 &amp;&amp; balance &lt;= MAX_BALANCE;</span>
<span class="w"> </span>
<span class="w"> </span><span class="c1">//@ assignable balance;</span>
<span class="w"> </span><span class="c1">//@ ensures balance == 0;</span>
<span class="w"> </span><span class="kd">public</span><span class="w"> </span><span class="nf">BankingExample</span><span class="p">()</span>
<span class="w"> </span><span class="p">{</span>
<span class="w"> </span><span class="k">this</span><span class="p">.</span><span class="na">balance</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">0</span><span class="p">;</span>
<span class="w"> </span><span class="p">}</span>
<span class="w"> </span>
<span class="w"> </span><span class="c1">//@ requires 0 &lt; amount &amp;&amp; amount + balance &lt; MAX_BALANCE;</span>
<span class="w"> </span><span class="c1">//@ assignable balance;</span>
<span class="w"> </span><span class="c1">//@ ensures balance == \old(balance) + amount;</span>
<span class="w"> </span><span class="kd">public</span><span class="w"> </span><span class="kt">void</span><span class="w"> </span><span class="nf">credit</span><span class="p">(</span><span class="kd">final</span><span class="w"> </span><span class="kt">int</span><span class="w"> </span><span class="n">amount</span><span class="p">)</span>
<span class="w"> </span><span class="p">{</span>
<span class="w"> </span><span class="k">this</span><span class="p">.</span><span class="na">balance</span><span class="w"> </span><span class="o">+=</span><span class="w"> </span><span class="n">amount</span><span class="p">;</span>
<span class="w"> </span><span class="p">}</span>
<span class="w"> </span>
<span class="w"> </span><span class="c1">//@ requires 0 &lt; amount &amp;&amp; amount &lt;= balance;</span>
<span class="w"> </span><span class="c1">//@ assignable balance;</span>
<span class="w"> </span><span class="c1">//@ ensures balance == \old(balance) - amount;</span>
<span class="w"> </span><span class="kd">public</span><span class="w"> </span><span class="kt">void</span><span class="w"> </span><span class="nf">debit</span><span class="p">(</span><span class="kd">final</span><span class="w"> </span><span class="kt">int</span><span class="w"> </span><span class="n">amount</span><span class="p">)</span>
<span class="w"> </span><span class="p">{</span>
<span class="w"> </span><span class="k">this</span><span class="p">.</span><span class="na">balance</span><span class="w"> </span><span class="o">-=</span><span class="w"> </span><span class="n">amount</span><span class="p">;</span>
<span class="w"> </span><span class="p">}</span>
<span class="w"> </span>
<span class="w"> </span><span class="c1">//@ ensures isLocked == true;</span>
<span class="w"> </span><span class="kd">public</span><span class="w"> </span><span class="kt">void</span><span class="w"> </span><span class="nf">lockAccount</span><span class="p">()</span>
<span class="w"> </span><span class="p">{</span>
<span class="w"> </span><span class="k">this</span><span class="p">.</span><span class="na">isLocked</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="kc">true</span><span class="p">;</span>
<span class="w"> </span><span class="p">}</span>
<span class="w"> </span>
<span class="w"> </span><span class="c1">//@ requires !isLocked;</span>
<span class="w"> </span><span class="c1">//@ ensures \result == balance;</span>
<span class="w"> </span><span class="c1">//@ also</span>
<span class="w"> </span><span class="c1">//@ requires isLocked;</span>
<span class="w"> </span><span class="c1">//@ signals_only BankingException;</span>
<span class="w"> </span><span class="kd">public</span><span class="w"> </span><span class="cm">/*@ pure @*/</span><span class="w"> </span><span class="kt">int</span><span class="w"> </span><span class="nf">getBalance</span><span class="p">()</span><span class="w"> </span><span class="kd">throws</span><span class="w"> </span><span class="n">BankingException</span>
<span class="w"> </span><span class="p">{</span>
<span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="p">(</span><span class="o">!</span><span class="k">this</span><span class="p">.</span><span class="na">isLocked</span><span class="p">)</span>
<span class="w"> </span><span class="p">{</span>
<span class="w"> </span><span class="k">return</span><span class="w"> </span><span class="k">this</span><span class="p">.</span><span class="na">balance</span><span class="p">;</span>
<span class="w"> </span><span class="p">}</span>
<span class="w"> </span><span class="k">else</span>
<span class="w"> </span><span class="p">{</span>
<span class="w"> </span><span class="k">throw</span><span class="w"> </span><span class="k">new</span><span class="w"> </span><span class="n">BankingException</span><span class="p">();</span>
<span class="w"> </span><span class="p">}</span>
<span class="w"> </span><span class="p">}</span>
<span class="p">}</span>
</pre></div>
<p>Full documentation of JML syntax is available <a rel="nofollow" class="external text" href="http://jmlspecs.org/jmlrefman/jmlrefman_toc.html">in the JML Reference Manual</a>.
</p>
<div class="mw-heading mw-heading2"><h2 id="Tool_support">Tool support</h2></div>
<p>A variety of tools provide functionality based on JML annotations. The Iowa State JML tools provide an assertion checking <a href="Compiler" title="Compiler">compiler</a> <code>jmlc</code> which converts JML annotations into runtime assertions, a documentation generator <code>jmldoc</code> which produces <a href="Javadoc" title="Javadoc">Javadoc</a> documentation augmented with extra information from JML annotations, and a unit test generator <code>jmlunit</code> which generates <a href="JUnit" title="JUnit">JUnit</a> test code from JML annotations.
</p><p>Independent groups are working on tools that make use of JML annotations. These include:
</p>
<ul><li><a href="ESC/Java2" class="mw-redirect" title="ESC/Java2">ESC/Java2</a> <a rel="nofollow" class="external autonumber" href="https://web.archive.org/web/20051016013145/http://secure.ucd.ie/products/opensource/ESCJava2/">[1]</a>, an extended static checker which uses JML annotations to perform more rigorous static checking than is otherwise possible.</li>
<li><a rel="nofollow" class="external text" href="http://www.openjml.org/">OpenJML</a> declares itself the successor of ESC/Java2.</li>
<li><a rel="nofollow" class="external text" href="http://pag.csail.mit.edu/daikon/">Daikon</a>, a dynamic invariant generator.</li>
<li><a href="KeY" title="KeY">KeY</a>, which provides an open source theorem prover with a JML front-end and an <a href="Eclipse_(software)" title="Eclipse (software)">Eclipse</a> plug-in (<a rel="nofollow" class="external text" href="http://www.key-project.org/eclipse/JMLEditing/">JML Editing</a>) with support for <a href="Syntax_highlighting" title="Syntax highlighting">syntax highlighting</a> of JML.</li>
<li><a rel="nofollow" class="external text" href="http://krakatoa.lri.fr">Krakatoa</a>, a static verification tool based on the <a rel="nofollow" class="external text" href="http://why.lri.fr">Why</a> verification platform and using the <a href="Coq_(software)" class="mw-redirect" title="Coq (software)">Coq</a> proof assistant.</li>
<li><a rel="nofollow" class="external text" href="http://jmleclipse.projects.cis.ksu.edu/">JMLEclipse</a>, a plugin for the Eclipse integrated development environment with support for JML syntax and interfaces to various tools that make use of JML annotations.</li>
<li><a rel="nofollow" class="external text" href="http://www.sireum.org/?q=node/21/">Sireum/Kiasan</a>, a symbolic execution based static analyzer which supports JML as a contract language.</li>
<li><a rel="nofollow" class="external text" href="http://www.eecs.ucf.edu/~leavens/JML2/docs/man/jmlunit.html">JMLUnit</a>, a tool to generate files for running JUnit tests on JML annotated Java files.</li>
<li><a rel="nofollow" class="external text" href="https://web.archive.org/web/20110706084805/http://www.dc.uba.ar/inv/grupos/rfm_folder/TACO">TACO</a>, an open source program analysis tool that statically checks the compliance of a Java program against its Java Modeling Language specification.</li></ul>
<div class="mw-heading mw-heading2"><h2 id="References">References</h2></div>
<ul><li><a href="Gary_T._Leavens" title="Gary T. Leavens">Gary T. Leavens</a> and Yoonsik Cheon. <i>Design by Contract with JML</i>; Draft tutorial.</li>
<li><a href="Gary_T._Leavens" title="Gary T. Leavens">Gary T. Leavens</a>, Albert L. Baker, and Clyde Ruby. <i>JML: A Notation for Detailed Design</i>; in Haim Kilov, <a href="Bernhard_Rumpe" title="Bernhard Rumpe">Bernhard Rumpe</a>, and Ian Simmonds (editors), <i>Behavioral Specifications of Businesses and Systems</i>, Kluwer, 1999, chapter 12, pages 175-188.</li>
<li><a href="Gary_T._Leavens" title="Gary T. Leavens">Gary T. Leavens</a>, Erik Poll, Curtis Clifton, Yoonsik Cheon, Clyde Ruby, David Cok, Peter Müller, Joseph Kiniry, Patrice Chalin, and Daniel M. Zimmerman. JML Reference Manual (DRAFT), September 2009. <a rel="nofollow" class="external text" href="http://www.jmlspecs.org/jmlrefman/jmlrefman_toc.html">HTML</a></li>
<li><a href="Marieke_Huisman" title="Marieke Huisman">Marieke Huisman</a>, Wolfgang Ahrendt, Daniel Bruns, and Martin Hentschel. <i>Formal specification with JML</i>. 2014. <a rel="nofollow" class="external text" href="http://primo.bibliothek.kit.edu/primo_library/libweb/action/dlDisplay.do?vid=KIT&amp;docId=KITSRCE1000041881&amp;tab=kit_evastar&amp;srt=date">download (CC-BY-NC-ND)</a></li></ul>
<div class="mw-heading mw-heading2"><h2 id="External_links">External links</h2></div>
<ul><li><a rel="nofollow" class="external text" href="http://www.eecs.ucf.edu/~leavens/JML/index.shtml">JML website</a></li></ul></div><!--htdig_noindex--><div><div class="zim-footer">
This article is issued from <a class="external text" title="Last edited on 2024-04-04" href="https://en.wikipedia.org/wiki/?title=Java_Modeling_Language&amp;oldid=1217242146">Wikipedia</a>. The text is available under <a class="external text" href="https://creativecommons.org/licenses/by-sa/4.0/deed.en">Creative Commons Attribution-Share Alike 4.0</a> unless otherwise noted. Additional terms may apply for the media files.
</div>
</div><!--/htdig_noindex--></div>
</div>
</main>
</div>
</div>
</div>

</body></html>